package 剑指Offer1;

public class _24连续子数组的最大和 {
    /*
        dp(i):以nums[i]结尾的最大子数组和
     */
    public int maxSubArray(int[] nums) {
        if(nums == null || nums.length == 0) return 0;
        int[] dp = new int[nums.length];
        int max = dp[0] = nums[0]; //base case
        for(int i=1;i<dp.length;++i){
            if(dp[i-1]<=0){
                dp[i] = nums[i];
            }else{
                dp[i] = dp[i-1] + nums[i];
            }
            max = Math.max(max,dp[i]);
        }
        return max;
    }
}
